Dynomotion

Group: DynoMotion Message: 2625 From: bradodarb Date: 12/6/2011
Subject: MAIN_STATUS .net
I've added interop members to access the MAIN_STATUS structure in the .net dlls

It is not quite right(or at all). I must not be initializing something right, When I try to read bitstate::

int bank = 0;
if (index > 31)
{
bank = 1;
index -= 31;
}
int retval = MainStatus.BitsState[bank] & (1<<index);
return retval;

It always returns false, even when I toggle the bits in KMotion. In fact, MainStatus.BitsState always contains [0,0]...


To test things out I put this in the c# console app::

_Controller.UpdateMainStatus();
while (true)
{
var val = _Controller.MainStatus.GetBitsState(47);

Console.WriteLine(val.ToString());

Thread.Sleep(500);
_Controller.UpdateMainStatus();
}


Am I missing something here?


-Brad
Group: DynoMotion Message: 2626 From: bradodarb Date: 12/6/2011
Subject: Re: MAIN_STATUS .net
Oops, forgot to mention I uploaded KMotion_dotNet

Here::
http://sourceforge.net/projects/cnctw/files/DynoMotion%20c%23/KMotion_dotNet.zip/download


-Brad Murry
--- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@...> wrote:
>
> I've added interop members to access the MAIN_STATUS structure in the .net dlls
>
> It is not quite right(or at all). I must not be initializing something right, When I try to read bitstate::
>
> int bank = 0;
> if (index > 31)
> {
> bank = 1;
> index -= 31;
> }
> int retval = MainStatus.BitsState[bank] & (1<<index);
> return retval;
>
> It always returns false, even when I toggle the bits in KMotion. In fact, MainStatus.BitsState always contains [0,0]...
>
>
> To test things out I put this in the c# console app::
>
> _Controller.UpdateMainStatus();
> while (true)
> {
> var val = _Controller.MainStatus.GetBitsState(47);
>
> Console.WriteLine(val.ToString());
>
> Thread.Sleep(500);
> _Controller.UpdateMainStatus();
> }
>
>
> Am I missing something here?
>
>
> -Brad
>
Group: DynoMotion Message: 2630 From: Tom Kerekes Date: 12/6/2011
Subject: Re: MAIN_STATUS .net
Hi Brad,
 
It looks like you are not doing anything with the received data.  All you are sending is the "GetStatus" command. 
 
/// <summary>
/// Makes the call to update the shared MAIN_STATUS structure
/// </summary>
public void UpdateMainStatus()
{
WriteLine(
"GetStatus");
}
#endregion
 
 
How did you imagine the data was getting from KFLOP to the PC?  :}   Or am I missing something?  When KFLOP receives this it will send back about 400 bytes of hexidecimal data which represents the binary image of the data structure. It is the application's responsibility to receive this data and place it (overlay it) into the MainStatus structure. Hmm C# proably won't like us doing stuff like that. KMotion does it in the function:
int
CKMotionCNCDlg::GetStatus()
 
Maybe we should duplicate (or move it) into KMotionDLL or KMotion_dotNet_Interop.
 
Also this function assumes that the Token has been obtained so the command and many lines of data will all come back to this Thread/Process/Code.
 
Regards
TK
 
 
 
 
Group: DynoMotion Message: 2633 From: Brad Murry Date: 12/7/2011
Subject: Re: MAIN_STATUS .net

Durr…. Forgot a little implementation there ;).  After a couple fruitless hours trying to hydrate the structure on the .net side(without unsafe blocks) I threw it in on the interop side(pretty much the same as you do on KMCNC).

 

I added a couple inline functions for the bit twiddling and now get good results, though I will most likely remove them-send the fully packed int values back to .net and twiddle ‘em over there so multiple values can be collected with one dll call.

 

Maybe I’ll leave the current stuff in and add the bulk value methods so we can do both…

 

 

Did I hear you right that this should be contained in a WaitToken()….ReleaseToken()?

 

 

 

 

Yes, I think this MAIN_STATUS functionality should probably be placed in KMotion.dll so it can be used by many applications.

 

 

-Brad

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of Tom Kerekes
Sent: Tuesday, December 06, 2011 11:08 PM
To: DynoMotion@yahoogroups.com
Subject: Re: [DynoMotion] Re: MAIN_STATUS .net

 

 

Hi Brad,

 

It looks like you are not doing anything with the received data.  All you are sending is the "GetStatus" command. 

 

/// <summary>

/// Makes the call to update the shared MAIN_STATUS structure

/// </summary>

public void UpdateMainStatus()

{

WriteLine(

"GetStatus");

}

#endregion

 

 

How did you imagine the data was getting from KFLOP to the PC?  :}   Or am I missing something?  When KFLOP receives this it will send back about 400 bytes of hexidecimal data which represents the binary image of the data structure. It is the application's responsibility to receive this data and place it (overlay it) into the MainStatus structure. Hmm C# proably won't like us doing stuff like that. KMotion does it in the function:

int

CKMotionCNCDlg::GetStatus()

 

Maybe we should duplicate (or move it) into KMotionDLL or KMotion_dotNet_Interop.

 

Also this function assumes that the Token has been obtained so the command and many lines of data will all come back to this Thread/Process/Code.

 

Regards

TK

 

 

 

 

From: bradodarb <bradodarb@...>
To: DynoMotion@yahoogroups.com
Sent: Tuesday, December 6, 2011 8:45 PM
Subject: [DynoMotion] Re: MAIN_STATUS .net

 

Oops, forgot to mention I uploaded KMotion_dotNet

Here::
http://sourceforge.net/projects/cnctw/files/DynoMotion%20c%23/KMotion_dotNet.zip/download

-Brad Murry

--- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@...> wrote:
>
> I've added interop members to access the MAIN_STATUS structure in the .net dlls
>
> It is not quite right(or at all). I must not be initializing something right, When I try to read bitstate::
>
> int bank = 0;
> if (index > 31)
> {
> bank = 1;
> index -= 31;
> }
> int retval = MainStatus.BitsState[bank] & (1<<index);
> return retval;
>
> It always returns false, even when I toggle the bits in KMotion. In fact, MainStatus.BitsState always contains [0,0]...
>
>
> To test things out I put this in the c# console app::
>
> _Controller.UpdateMainStatus();
> while (true)
> {
> var val = _Controller.MainStatus.GetBitsState(47);
>
> Console.WriteLine(val.ToString());
>
> Thread.Sleep(500);
> _Controller.UpdateMainStatus();
> }
>
>
> Am I missing something here?
>
>
> -Brad
>

 

Group: DynoMotion Message: 2634 From: Tom Kerekes Date: 12/7/2011
Subject: Re: MAIN_STATUS .net
Hi Brad,
 
That's good.  Yes it should be contained in a WaitToken/ReleaseToken that way the entire data set will be recieved by the one thread.  Also as I think we discussed the other day KMotionCNC uses a 100ms WaitToken timeout because updating status/screens is sort of a best effort requirement and is not essential.  It also will tell us if a board is present or not.   
 
Regards
TK